package com.adnaan.restaurant.controller;

import com.adnaan.restaurant.common.untils.PageResult;
import com.adnaan.restaurant.common.untils.R;
import com.adnaan.restaurant.entity.ResOrder;
import com.adnaan.restaurant.service.IResOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author: adnaan
 * create: 2023-12-10 20:25
 * Description:
 */
@Tag(name = "订单接口", description = "订单相关功能")
@RestController
@RequestMapping("/restaurant/order")
public class ResOrderController {

    @Autowired
    private IResOrderService resOrderService;

    @Operation(summary = "我的订单")
    @GetMapping("/getMyOrder")
    public R getMyOrder(@RequestParam Long userId,
                        @RequestParam Integer pageNum,
                        @RequestParam Integer pageSize) {
        PageResult list = resOrderService.getMyOrder(userId, pageNum, pageSize);
        return R.success(list);
    }

    @Operation(summary = "下单")
    @PostMapping("/buy")
    public R buy(@RequestBody ResOrder resOrder) {
        int ok = resOrderService.buy(resOrder);
        if (ok > 0) {
            return R.success("购买成功");
        } else {
            return R.error(500, "购买失败");
        }
    }
}
